<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
	<!-- menu -->
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">			
	<h3><?php echo $this->params->get('page_title'); ?></h3>
	<hr />
	<?php
	$priceformat 	= OwnserviceHelper::getParams('price_format', '#,###.##');
	$dateformat  	= OwnserviceHelper::getParams('date_format', '%d/%m/%Y');
	$timeformat	 	= OwnserviceHelper::getParams('time_format', '%H:%i:%s');
	$row 			= $this->row;
	$instance 		=& JFactory::getDate($row->created); 
	$link_user 		= JRoute::_('index.php?option=com_ownservice&controller=member&task=detail&id='.$row->memberid);
	$link_account	= JRoute::_('index.php?option=com_ownservice&controller=account&task=detail&id='.$row->a_id);
	?>
	
	<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm">
	<table width="100%" cellpadding="1" cellspacing="1">
	<tr>
		<td>
		<table class="admintable">
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_RECEIVER_NO'); ?></td>
				<td><?php echo $row->transactionid; ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_STATUS'); ?></td>
				<td align="left">
					<?php
						echo OwnserviceHelper::getState($row->state); 
					?>
				</td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_CREATED_DATE_TIME'); ?></td>
				<td><?php echo JHTML::_('date', $row->created, $dateformat).' '.date($timeformat, $instance->toUnix()); ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_REQUESTED_DATE_TIME'); ?></td>
				<td>
					<?php 
						if($row->requested_date != $this->nullDate) {
							$instance =& JFactory::getDate($row->requested_date);
							echo JHTML::_('date', $row->requested_date, $dateformat).' '.date($timeformat, $instance->toUnix());
						}
					?>
				</td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_APPROVAL_DATE_TIME'); ?></td>
				<td>
					<?php 
						if($row->approval_date != $this->nullDate) {
							$instance =& JFactory::getDate($row->approval_date);
							echo JHTML::_('date', $row->approval_date, $dateformat).' '.date($timeformat, $instance->toUnix());
						}
					?>
				</td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_COMPLETION_DATE_TIME'); ?></td>
				<td>
					<?php 
						if($row->completion_date != $this->nullDate) {
							$instance =& JFactory::getDate($row->completion_date);
							echo JHTML::_('date', $row->completion_date, $dateformat).' '.date($timeformat, $instance->toUnix());
						}
					?>
				</td>
			</tr>
			<?php if( $this->access->canApprovalTransferred && $row->id && ($row->state == 3 || $row->state == 5) ): ?>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_STAFF_TRANSFER'); ?></td>
				<td align="left"><?php echo $row->firstname.' '.$row->lastname; ?></td>
			</tr>
			<?php endif; ?>
			<tr>
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td colspan="2"><h3><?php echo JText::_('OWNSERVICE_SENDER'); ?></h3></td>
			</tr>
			<tr>
				<td class="key">
					<?php echo JText::_('OWNSERVICE_BRANCH'); ?>
				</td>
				<td>
					<?php echo $row->b_code; ?>
				</td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_SENDER'); ?></td>
				<td><a href="<?php echo $link_user; ?>"><?php echo $row->name.' ('.$row->username.')'; ?></a></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_ADDRESS'); ?></td>
				<td><?php echo $row->p_address.' '.$row->p_city.' '.$row->p_state.' '.$row->p_postcode.' '.$row->p_country; ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_PHONE'); ?></td>
				<td><?php echo $row->p_phone_no; ?></td>
			</tr>
			<tr>
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td colspan="2"><h3><?php echo JText::_('OWNSERVICE_PAYEE'); ?></h3></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_ACCOUNT_NAME'); ?></td>
				<td><a href="<?php echo $link_account; ?>"><?php echo $row->account_name; ?></a></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?></td>
				<td><?php echo OwnserviceHelper::accountFormat($row->account); ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_ACCOUNT_TYPE'); ?></td>
				<td><?php echo $row->account_type; ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_BANK_NAME'); ?></td>
				<td><?php echo $row->bank_name; ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_BRANCH_NAME'); ?></td>
				<td><?php echo $row->branch_name; ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_ADDRESS'); ?></td>
				<td><?php echo $row->a_address.' '.$row->a_city.' '.$row->a_state.' '.$row->a_postcode.' '.$row->a_country; ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_PHONE'); ?></td>
				<td><?php echo $row->a_phone_no; ?></td>
			</tr>
			<tr>
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td colspan="2"><h3><?php echo JText::_('OWNSERVICE_TRANSFER'); ?></h3></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_AMOUNT_TRANSFER'); ?></td>
				<td>
				<div style="width: 150px;">
					<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?> AUD
				</div>
				</td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_FEE'); ?></td>
				<td>
					<?php
						$color = '';
						if($row->extrafee > 0.00 ){
							$color = 'red';
						} else if($row->extrafee < 0.00 ) {
							$color = 'green';
						}
					?>
					<div style="width: 150px;">
						<span class="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,($row->fee+$row->extrafee)); ?></span> AUD
					</div>
				</td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_EXCHANGE_RATE'); ?></td>
				<td>
				<?php
					$color = '';
					if($row->extrarate > 0.00 ){
						$color = 'red';
					} else if($row->extrarate < 0.00 ) {
						$color = 'green';
					}
				?>
				<div style="width: 150px;">
					<?php if(!$row->iscore): ?>
					<div style="border-bottom: 1px solid;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,($row->rate_th)); ?> THB
					</div>
					<?php endif; ?>
					<div>
					<span class="<?php echo $color; ?>">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,($row->rate+$row->extrarate)); ?>
					</span> <?php echo $row->rate_code; ?>
					</div>
				</div>
				</td>
			</tr>
			<tr>
				<td class="key"> <?php echo JText::_('OWNSERVICE_BANK_FEE'); ?></td>
				<td>
					<?php 
						$color = '';
						if($row->extrabfee > 0.00 ){
							$color = 'red';
						} else if($row->extrabfee < 0.00 ) {
							$color = 'green';
						}
					?>
					<div style="width: 150px;">
					<span class="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,($row->bankfee+$row->extrabfee)); ?></span> <?php echo $row->rate_code; ?>
					</div>
				</td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_TOTAL_EXCHANGE'); ?></td>
				<td>
					<?php
						/*$color = '';
						$total = 0;
						if($row->extratotal > 0.00 ){
							$color = 'red';
							$total = $row->extratotal;
						} else {
							$total = ($row->amount * ($row->rate+$row->extrarate));
						}*/
					?>
					<div style="width: 150px;">
					<?php if(!$row->iscore): ?>
					<div style="border-bottom: 1px solid;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
					</div>
					<?php endif; ?>
					<div>
					<span class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
						<?php 
							if($row->extratotal > 0.00 ){
								echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal);
							} else {
								echo OwnserviceHelper::moneyFormat($priceformat,( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))); 
							}
						?>
					</span> <?php echo $row->rate_code; ?>
					</div>
					</div>
				</td>
			</tr>
			<tr>
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td colspan="2"><h3><?php echo JText::_('OWNSERVICE_REASON'); ?></h3></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_REASON'); ?> </td>
				<td><?php echo OwnserviceHelper::getReason($row->reason); ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_COMMENT'); ?></td>
				<td><?php echo $row->comment; ?></td>
			</tr>
			<tr>
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_TRANSACTION_BRANCH'); ?></td>
				<td><?php echo $row->tb_code; ?></td>
			</tr>
			<tr>
				<td class="key"><?php echo JText::_('OWNSERVICE_STAFF_ID'); ?></td>
				<td><?php echo $row->cusername; ?></td>
			</tr>
			<tr>
				<td colspan="2"><hr /></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="button" name="cancel" value="<?php echo JText::_('OWNSERVICE_CLOSE'); ?>" onClick="javascript:submitbutton('cancelledtransactions');" /> 
				</td>
			</tr>
		</table>
		</td>
	</tr>
	</table>
	<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
	<input type="hidden" name="status" value="" />
	<input type="hidden" name="option" value="com_ownservice" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
	<input type="hidden" name="controller" value="transaction" />
	<input type="hidden" name="view" value="transaction" />
	<?php echo JHTML::_( 'form.token' ); ?>
	</form>
	</div>
</div>